package com.techsoul.module.baoli.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.log.annotation.Log;
import com.techsoul.common.log.enums.OperationTypeEnum;
import com.techsoul.module.baoli.pojo.param.FinCreditBillSaveParam;
import com.techsoul.module.baoli.pojo.param.FinFinanceApplySaveParam;
import com.techsoul.module.baoli.pojo.param.FinFinanceApplySearchParam;
import com.techsoul.module.baoli.service.IFinFinanceApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * 融资申请单 Controller
 *
 * @author liuen
 * @date 2022-03-28
 */
@Api(tags = "融资申请单")
@RestController
@RequestMapping("/baoli/finFinanceApply")
public class FinFinanceApplyController {

    @Autowired
    private Result result;
    
    @Autowired
    private IFinFinanceApplyService service;

    @ApiOperation("新增")
    @Log(title = "融资申请单", operationType = OperationTypeEnum.INSERT)
    @PreAuthorize("hasAnyAuthority('baoli:finFinanceApply:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody FinFinanceApplySaveParam params) {
        return result.success(this.service.insert(params));
    }

    @ApiOperation("批量删除（多个用逗号隔开）")
    @Log(title = "融资申请单", operationType = OperationTypeEnum.DELETE)
    @PreAuthorize("hasAnyAuthority('baoli:finFinanceApply:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @Log(title = "融资申请单", operationType = OperationTypeEnum.UPDATE)
    @PreAuthorize("hasAnyAuthority('baoli:finFinanceApply:update')")
    @PutMapping
    public Result update(@Valid @RequestBody FinFinanceApplySaveParam params) {
        return result.success(this.service.update(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('baoli:finFinanceApply:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
    @PreAuthorize("hasAnyAuthority('baoli:finFinanceApply:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody FinFinanceApplySearchParam params) {
        return result.success(this.service.findAll(params));
    }
    @ApiOperation("结算确认")
    @PreAuthorize("hasAnyAuthority('baoli:finFinanceApply:settlementConfirm')")
    @PostMapping("/settlementConfirm")
    public Result settlementConfirm(@RequestBody FinFinanceApplySaveParam params) {

        String ret = service.settlementConfirm(params);
        return result.success();

    }
    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('baoli:finFinanceApply:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody FinFinanceApplySearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        if(params.getStatus()!=null&&params.getStatus()!=""){
            if(params.getStatus().equals("all")){
                params.setStatus(null);
            }
        }
        return result.success(this.service.findAll(params, current, pageSize));
    }

}
